package org.xlx.xlx_oa.common;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class ResponseBean<T> {
    private int code; //成功 200  失败 400
    private String msg;
    private T data;
    private String errData;

    @SuppressWarnings("hiding")
    public <T> ResponseBean() {
    }

    public ResponseBean(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseBean(int code, String msg, T data, String errData) {
        this.code = code;
        this.msg = msg;
        this.errData = errData;
    }

    public static <T> ResponseBean<T> successFactory() {
        return new ResponseBean<T>(200, "success", null);
    }

    public static <T> ResponseBean<T> successFactory(T t) {
        return new ResponseBean<T>(200, "success", t);
    }

    public static <T> ResponseBean<T> successFactory(String msg, T t) {
        return new ResponseBean<T>(200, msg, t);
    }

    public static <T> ResponseBean<T> failureFactory(T t) {
        return new ResponseBean<T>(400, "failure", t);
    }

    public static <T> ResponseBean<T> failureFactory(String msg, T t) {
        return new ResponseBean<T>(400, msg, t);
    }
}
